
from bs4 import BeautifulSoup
import urllib2, re, os, time
import pickle as pickle
import utils
#globals
LOCAL_DIR = r"C:\Users\Danny\Documents\lol_team_tool"
COUNTER_DIR = os.path.join(LOCAL_DIR, "counters")

def get_stats_dict_from_user_page(soup):
	all_stats = {}
	for table in soup.find_all("table", id="ranked_stats"):
	   	table_name = str(table["class"][1])
		headers = []
		games = []
		for th in table.thead.find_all("th"):
			headers.append(str(th.string))
		for tr in table.find_all("tr"):
			values = []
			for i, td in enumerate(tr.find_all("td")):
				if i == 0:
					values.append(str(list(td.find_all("a"))[1].string))
				else:
					values.append(str(td.string))
			if values:
				games.append(dict(zip(headers, values)))
		all_stats[table_name] = games
	return all_stats

'''
url = os.path.join(COUNTER_DIR, "champ_list.html")
f = open(url)
content = f.read()
f.close()
soup = BeautifulSoup(content)
'''
text = """
 Blitzcrank	Tank	80	40	50	60	2009-09-02	3150	975
 Cho'Gath	Tank	40	30	80	70	2009-06-26	1350	585
 Nidalee	Fighter	40	50	70	70	2009-12-17	3150	975
 Rammus	Tank	100	40	50	50	2009-07-10	3150	690
 Tristana	R-DPS	40	90	30	30	2009-02-21	1350	585
 Udyr	Fighter	80	60	50	70	2009-12-02	3150	975
 Zilean	Mage	50	20	80	40	2009-04-18	1350	585
 Gragas	Fighter	90	40	60	60	2010-02-02	3150	975
 Kennen	Mage	30	40	70	50	2010-04-08	4800	975
 Garen	Fighter	40	90	20	20	2010-04-27	450	260
 Trundle	Fighter	60	70	20	50	2010-12-01	4800	850
 Sivir	R-DPS	30	90	10	30	2009-02-21	450	260
 Rumble	Mage	60	30	80	80	2011-04-26	4800	975
 Wukong	Fighter	50	80	20	30	2011-07-26	6300	975
 Fizz	Mage	40	30	70	60	2011-11-15	6300	975
 Viktor	Mage	50	20	80	70	2011-12-28	6300	975
 Ziggs	Mage	30	50	90	80	2012-02-01	6300	975
 Lulu	Support	50	40	70	50	2012-03-20	6300	975
 Ashe	R-DPS	30	70	20	40	2009-02-21	450	260
 Jax	M-DPS	50	70	70	60	2009-02-21	1350	585
 Ezreal	R-DPS	40	50	70	80	2010-03-16	6300	975
 Rengar	M-DPS	40	60	20	50	2012-08-21	6300	975
 Syndra	Mage	50	20	90	90	2012-09-13	6300	975
 Tryndamere	M-DPS	50	100	20	60	2009-05-01	1350	585
 Soraka	Support	50	20	70	30	2009-02-21	450	260
 Twisted Fate	Mage	20	60	60	90	2009-02-21	1350	585
 Karthus	Mage	20	20	100	80	2009-06-12	3150	975
 Anivia	Mage	50	10	100	70	2009-07-10	3150	790
 Nasus	Fighter	50	70	60	20	2009-10-01	1350	585
 Sion	Fighter	80	50	70	40	2009-02-21	1350	585
 Olaf	Fighter	50	90	30	40	2010-06-09	3150	975
 Urgot	R-DPS	50	80	30	80	2010-08-24	3150	975
 Evelynn	M-DPS	20	40	70	80	2009-05-01	1350	585
 Annie	Mage	30	20	100	40	2009-02-21	450	260
 Twitch	R-DPS	20	90	30	80	2009-05-01	3150	975
 Brand	Mage	20	20	90	60	2011-04-12	6300	975
 Taric	Support	80	40	50	30	2009-08-19	1350	585
 Yorick	Fighter	60	60	60	30	2011-06-22	6300	975
 Skarner	Fighter	60	70	50	50	2011-08-09	6300	975
 Riven	Fighter	50	80	10	40	2011-09-14	6300	975
 Gangplank	Fighter	60	70	40	50	2009-08-19	3150	975
 Volibear	Fighter	70	60	40	40	2011-11-29	6300	975
 Ahri	Mage	40	30	80	80	2011-12-14	6300	975
 Sejuani	Tank	70	50	60	40	2012-01-17	6300	975
 Hecarim	Fighter	60	80	40	50	2012-04-18	6300	975
 Darius	Fighter	50	90	20	30	2012-05-23	6300	975
 Amumu	Tank	60	20	80	40	2009-06-26	1350	585
 Pantheon	M-DPS	30	90	30	30	2010-02-02	3150	975
 Renekton	Fighter	50	90	20	30	2011-01-19	6300	975
 Warwick	Fighter	40	70	40	20	2009-02-21	1350	585
 Diana	M-DPS	60	70	80	40	2012-08-07	6300	975
 Cassiopeia	Mage	30	20	90	100	2010-12-14	4800	880
 Ryze	Mage	20	20	100	30	2009-02-21	450	260
 Miss Fortune	R-DPS	20	80	50	30	2010-09-08	4800	975
 Elise	Mage	50	60	70	80	2012-10-26	6300	975
 Kassadin	Mage	50	30	80	80	2009-08-07	3150	690
 Malphite	Fighter	60	50	70	30	2009-09-02	1350	585
 Heimerdinger	Mage	60	20	80	40	2009-10-10	3150	975
 Shaco	M-DPS	40	80	60	90	2009-10-10	3150	975
 Poppy	Fighter	50	40	80	60	2010-01-13	450	260
 Akali	M-DPS	30	50	80	60	2010-05-11	3150	975
 Sona	Support	50	20	80	10	2010-09-20	3150	975
 LeBlanc	Mage	40	10	100	90	2010-11-02	3150	975
 Katarina	M-DPS	30	40	90	30	2009-09-19	3150	975
 Maokai	Tank	80	30	60	40	2011-02-16	4800	790
 Orianna	Mage	30	40	90	100	2011-06-01	4800	975
 Xerath	Mage	30	10	100	60	2011-10-05	6300	975
 Graves	R-DPS	50	80	30	40	2011-10-19	6300	975
 Malzahar	Mage	20	20	90	60	2010-06-01	4800	975
 Fiddlesticks	Mage	30	20	90	50	2009-02-21	1350	585
 Nautilus	Tank	60	40	80	50	2012-02-14	6300	975
 Caitlyn	R-DPS	40	80	40	40	2011-01-04	4800	790
 Xin Zhao	M-DPS	60	80	30	30	2010-07-13	3150	975
 Jayce	Fighter	60	60	50	70	2012-07-07	6300	975
 Corki	R-DPS	30	80	60	70	2009-09-19	3150	790
 Mordekaiser	Mage	60	60	60	30	2010-02-24	3150	975
 Morgana	Mage	60	10	80	70	2009-02-21	1350	585
 Kha'Zix	M-DPS	40	90	60	70	2012-09-27	6300	975
 Lux	Mage	40	20	90	60	2010-10-19	3150	975
 Vladimir	Mage	60	20	80	20	2010-07-27	6300	975
 Galio	Tank	70	30	60	40	2010-08-10	4800	975
 Zed	M-DPS	40	80	10	80	2012-11-13	6300	975
 Nami	Support	40	30	90	80	TBA		
 Master Yi	M-DPS	40	90	30	20	2009-02-21	450	260
 Nunu	Fighter	60	40	70	30	2009-02-21	450	260
 Singed	Tank	60	50	70	50	2009-04-18	1350	585
 Shen	Tank	90	30	30	30	2010-03-24	3150	975
 Swain	Mage	60	20	90	50	2010-10-05	4800	850
 Irelia	Fighter	40	70	50	50	2010-11-16	4800	975
 Karma	Support	70	10	80	80	2011-02-01	3150	975
 Jarvan IV	Fighter	80	60	30	50	2011-03-01	4800	975
 Nocturne	M-DPS	50	90	20	60	2011-03-16	6300	975
 Veigar	Mage	20	20	100	60	2009-07-24	1350	585
 Lee Sin	Fighter	50	80	30	80	2011-04-01	6300	975
 Kog'Maw	R-DPS	20	80	50	80	2010-06-24	4800	880
 Vayne	R-DPS	10	90	20	70	2011-05-10	6300	975
 Leona	Tank	80	40	30	40	2011-07-13	6300	975
 Kayle	Support	90	50	60	30	2009-02-21	450	260
 Talon	M-DPS	50	90	30	60	2011-08-24	6300	975
 Shyvana	Fighter	60	70	50	40	2011-11-01	6300	975
 Alistar	Tank	90	60	50	80	2009-02-21	1350	585
 Janna	Support	50	30	70	90	2009-09-02	1350	585
 Fiora	M-DPS	40	100	30	50	2012-02-29	6300	975
 Varus	R-DPS	30	70	40	60	2012-05-08	6300	975
 Draven	R-DPS	40	90	20	60	2012-06-06	6300	975
 Dr. Mundo	Fighter	70	50	60	40	2009-09-02	1350	585
 Teemo	R-DPS	30	50	70	40	2009-02-21	1350	585
 Zyra	Mage	30	40	80	70	2012-07-24	6300	975
"""
for line in text.split("\n"):
	_tmp = line.split("\t")
	if len(_tmp)>2:
		champ, role = _tmp[0], _tmp[1]
		print champ, role